package com.ruoyi.his.service.impl;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.his.domain.HisDept;
import com.ruoyi.his.mapper.HisDeptMapper;
import com.ruoyi.his.service.IHisDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HisDeptServiceImpl implements IHisDeptService {
    @Autowired
    private HisDeptMapper deptMapper;
    /**
     * 查询岗位信息集合
     *
     * @param dept 岗位信息
     * @return 岗位信息集合
     */
    public List<HisDept> selectDeptList(HisDept dept)
    {
        return deptMapper.selectDeptList(dept);
    }

    @Override
    public List<HisDept> selectDeptAll() {
        return deptMapper.selectDeptAll();
    }

    @Override
    public HisDept selectDeptById(Long deptId) {
        return deptMapper.selectDeptById(deptId);
    }

    @Override
    public List<Long> selectDeptListByUserId(Long userId) {
        return deptMapper.selectDeptListByUserId(userId);
    }
    /**
     * 校验科室名称是否唯一
     *
     * @param dept 岗位信息
     * @return 结果
     */

    @Override
    public boolean checkDeptNameUnique(HisDept dept) {
        Long postId = StringUtils.isNull(dept.getDeptId()) ? -1L : dept.getDeptId();
        HisDept info = deptMapper.checkDeptNameUnique(dept.getDeptName());
        if (StringUtils.isNotNull(info) && info.getDeptId().longValue() != postId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }
    @Override
    public int deleteDeptById(Long deptId) {
        return deptMapper.deleteDeptById(deptId);
    }

    @Override
    public int deleteDeptByIds(Long[] deptIds) {
        return deptMapper.deleteDeptByIds(deptIds);
    }

    @Override
    public int insertDept(HisDept dept) {
        return deptMapper.insertDept(dept);

    }

    @Override
    public int updateDept(HisDept dept) {
        return deptMapper.updateDept(dept);
    }


}
